import { Component } from '@angular/core';
import { News } from './model/news';
import { NewsService } from './service/news.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  nl:Array<News>;

  constructor(private newsservice:NewsService){
    this.nl=new Array();
  }

   //页面/组建加载时运行的方法
       ngOnInit() {
     this.loadnewslist();
  }

    private loadnewslist(){
      this.nl=new Array();

      this.newsservice.getNewsList()
       .then((data:any)=>{
          this.nl=data;
       })
    }


  
}
